package com.bawei.park2211a.rov


import androidx.appcompat.widget.SearchView
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bawei.base.mvvm.BaseActivity

import com.bawei.park2211a.adapter.ROVAdapter
import com.bawei.park2211a.databinding.ActivityRovactivityBinding
import dagger.hilt.android.AndroidEntryPoint

@Route(path = "/app/rov/ROVActivity")
@AndroidEntryPoint
class ROVActivity : BaseActivity<ActivityRovactivityBinding, ROVViewModel>() {
   private lateinit var rovAdapter: ROVAdapter
    override fun initView() {
        viewModel.carInfoId("津A55555")
        rovAdapter = ROVAdapter()
        binding.carRec.adapter = rovAdapter
        binding.carRec.layoutManager = LinearLayoutManager(this)
        binding.carSearch.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
            override fun onQueryTextSubmit(query: String?): Boolean {
                if (query != null)
                    viewModel.carInfoId(query)
                return true
            }

            override fun onQueryTextChange(newText: String?): Boolean {
                return true
            }

        })
        binding.carAdd.setOnClickListener {
            ARouter.getInstance().build("/app/rov/AddCarInfoActivity").navigation()
        }

    }

    override fun initData() {
        viewModel.carDetailSuccess.observe(this) {
            rovAdapter.data.clear()
            rovAdapter.data.add(it)
            rovAdapter.notifyItemChanged(0)
        }
    }
}